package com.soft.admin.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.soft.admin.dto.NewsDTO;
import com.soft.admin.service.NewsService;
import com.soft.support.PageParam;

@Controller
@RequestMapping(value = "/admin/news.do")
public class NewsController extends BaseController {
	private NewsService newsService;

	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request, NewsDTO params, 
			PageParam page) throws IOException {
		String res = this.newsService.get(params, page);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextochannel")
	public String getChannel(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.newsService.getChannel();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextouser")
	public String getUser(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.newsService.getUser();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "add")
	public String add(HttpServletResponse response, HttpServletRequest request, NewsDTO params) 
			throws IOException {
		String res = this.newsService.addOrEdit(request, params);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "edit")
	public String edit(HttpServletResponse response, HttpServletRequest request, NewsDTO params) 
			throws IOException {
		String res = this.newsService.addOrEdit(request, params);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "remove")
	public String remove(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.newsService.remove(request, id);
		response.getWriter().print(res);
		return null;
	}

	@Autowired
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
}
